home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15227 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: ccshst05.cs.uoguelph.ca!ccshst01!thay
  2. From: thay@uoguelph.ca (Toby K Hay)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: bubble sort walkthrough needed, please
  5. Date: 17 Apr 1996 20:56:02 GMT
  6. Organization: University of Guelph
  7. Message-ID: <4l3lt2$k3c@ccshst05.uoguelph.ca>
  8. References: <4l39b4$s2h@coranto.ucs.mun.ca>
  9. NNTP-Posting-Host: ccshst01.uoguelph.ca
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. J.Deeley (jdeeley@calvin.stemnet.nf.ca) wrote:
  13. : I am trying to understand how this bubble sort is working. I understand
  14. : the theory, and I understand how the whole thing works except for the
  15. : few lines under the comment /* now sort them using a bubble sort */
  16. : In other words, it's only the lines 
  17.  
  18. : for(a=1; a<count; a++)
  19. :                 for(b=count-1; b>=a;--b) 
  20.  
  21. : that I can't fathom. I've been working at this ever since last night and
  22. : I still don't get it. Could someone tell me what is going on in that
  23. : part?
  24.  
  25. Let a relative newcomer try.  The first line says do the following with 'a' 
  26. taking every value from 1 up to 'count-1'.  Using 'a' to index the array 
  27. 'item' will get you the values in the second position up to the position 
  28. numbered' count'.  The second line says do the following with 'b' taking 
  29. every value from 'count-1' down to 'a'.  Using 'b' to index the array 
  30. 'item' will get you the values in the position numbered 'count' down to 
  31. the position numbered 'a'.  'count-1' is used as a limit rather than 
  32. 'count' because the array 'item' is numbered starting at 0 as are all 
  33. arrays in C.  
  34. Toby Hay     thay@uoguelph.ca
  35.  
  36.  
  37.